package com.example.input;

import android.content.Intent;
import android.hardware.biometrics.BiometricManager;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.Objects;

public class FindPasswordBackActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_find_password_back);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        String phoneNumber = getIntent().getStringExtra("phoneNumber");

        EditText phoneNumberView = findViewById(R.id.phoneNumber);

        phoneNumberView.setText(phoneNumber);

        EditText newPasswordView = findViewById(R.id.newPassword);
        EditText newPasswordView2 = findViewById(R.id.newPassword2);

        findViewById(R.id.modifyPassword).setOnClickListener(view->{

            String newPassword = newPasswordView.getEditableText().toString();

            if (newPassword.isEmpty()){
                Toast.makeText(this,"密码不能为空",Toast.LENGTH_SHORT).show();

                return;
            }
            if (!Objects.equals(newPassword,newPasswordView2.getEditableText().toString())) {
                Toast.makeText(this,"两次密码不一致",Toast.LENGTH_SHORT).show();

                return;
            }
            Intent intent = new Intent();
            intent.putExtra("newPassword",newPassword);
            setResult(RESULT_OK,intent);
            Toast.makeText(this,"修改成功",Toast.LENGTH_SHORT).show();
            finish();
        });
    }
}